#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n,k;
vector<string> v[2505];

int cmp(string &s1,string &s2){
    return s1<s2;
}

signed main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++){
        string name;
        int c,a;
        cin>>name>>c;
        for(int j=0;j<c;j++){
            cin>>a;
            v[a].push_back(name);
        }
    }
    for(int i=1;i<=k;i++){
        cout<<i<<" "<<v[i].size()<<"\n";
        sort(v[i].begin(),v[i].end(),cmp);
        for(int j=0;j<v[i].size();j++)
            cout<<v[i][j]<<"\n";
    }
    return 0;
}
